home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / clipswap.zip / SWAP.C next >
C/C++ Source or Header  |  1993-04-01  |  4KB  |  159 lines

  1. #include <stdio.h>
  2. #include <dos2.h>
  3. #include "c:\c5\include\extend.h"
  4. /*
  5.  
  6.    
  7.    the two useful functions here are DisableSwap and EnableSwap. They do
  8.    the obvious thing...
  9.  
  10.    Clipper Functions: SWAPON and SWAPOFF return logical (see test code TEST.PRG)
  11.    Useful to stop user from swapping out of Clipper App in middle of reindexing
  12.    or to prevent dreaded deadlock situations which can be introduced via
  13.    DOSSWAP which were heretofore impossible in a multi-user Clipper App....
  14.  
  15.  
  16.    DisableSwap returns 1 if successful, 0 if dosswap not installed
  17.    EnableSwap  returns 1 if successful, 0 if dosswap not previously disabled
  18.  
  19.    Author: David Conway, CIBC Mortage Corp., Toronto Canada
  20.    Clipperized and MSCized by Kevin Burns, CIBC Mortgage Corp, Toronto Canada
  21.  
  22.    Swap.c is released into the public domain
  23.  
  24.    Compile the following in Borland C++ using the following compile options
  25.  
  26.             bcc -c -ml -Z -O -r -f- -i15 -1- -B
  27.  
  28.    You will require the modified dos.h header "dos2.h" which contain
  29.    the MSC function prototypes for _dos_setvect and _dos_getvect suitably
  30.    modified for Borland C++.
  31.  
  32.    _dos_setvect and _dos_getvect are the MSC equivalents
  33.    of the Borland functions setvect and getvect.
  34.  
  35.    Therefore, to link your clipper code you will require LLIBCA.LIB (ugh...)
  36.  
  37.  
  38. */
  39.  
  40.  
  41. void far* Detect_Switcher();
  42. void far notify();
  43.  
  44. void far interrupt hex2f(unsigned bp,unsigned  di,unsigned    si,unsigned  ds,
  45.                         unsigned  es,unsigned  dx,unsigned    cx,unsigned  bx,
  46.                         unsigned  ax,unsigned  ip,unsigned    cs,unsigned  flags);
  47.  
  48. /* swapinfo structure, detailing ASYNC API's we support
  49.         -- none at this time --.
  50. */
  51.  
  52. struct SWINFO{
  53.     int  word1;
  54.     int  word2;
  55.     int  word3;
  56.     int  word4;
  57.     int  word5;
  58.     int  word6;
  59. }swinfo={10,0,0,0,0,0};
  60.  
  61. struct SWCALLBACKINFO{
  62.     void far *dd1;
  63.     void (far *notptr)();
  64.     void far *reserved;
  65.     void far* swapinfo;
  66. }cbinfo={NULL,notify,NULL,&swinfo};
  67.  
  68. static void (far * callback)();
  69. static void (interrupt far *mplex)();
  70. static void (far* swapper)();
  71.  
  72.  
  73. CLIPPER SWAPON()
  74. {
  75. _retl(EnableSwap());
  76. }
  77.  
  78.  
  79. CLIPPER SWAPOFF()
  80. {
  81. _retl(DisableSwap());
  82. }
  83.  
  84.  
  85. int DisableSwap(void)
  86. {
  87.     union REGS regs;
  88.     struct SREGS segregs;
  89.     // use getvect(0x2f) for pure Borland C++
  90.     mplex = _dos_getvect(0x2f);
  91.     if(!mplex)
  92.     {
  93.         /* Error - swap not installed */
  94.         return(0);
  95.     }
  96.     if(!(swapper=(void far *)Detect_Switcher()))
  97.     {
  98.         /* Error - swap not installed */
  99.         return(0);
  100.     }
  101.  
  102.     callback = (void far *)mplex;
  103.     // use setvect(0x2f,hex2f) for pure Borland C++
  104.     _dos_setvect(0x2f,hex2f);
  105.     return (1);
  106. }
  107.  
  108. int EnableSwap(void)
  109. {
  110.     if(mplex!=NULL)
  111.     // use setvect(0x2f,mplex) for pure Borland C++
  112.        _dos_setvect(0x2f,mplex);
  113.     else
  114.        return(0);
  115.     return(1);
  116. }
  117.  
  118.  
  119. void far notify()
  120. {
  121.     asm{
  122.         push ds
  123.         mov ax, DGROUP
  124.         mov ds, ax
  125.     }
  126.     asm  pop ds
  127.     asm  mov ax, 1
  128. }
  129.  
  130. void far* Detect_Switcher ()
  131. {
  132.     asm {
  133.           mov bx, 0
  134.           mov di, 0
  135.           mov es, di
  136.           mov ax, 0x4b02
  137.           int 0x2f
  138.         }
  139.     return(MK_FP(_ES,_DI));
  140. }
  141.  
  142. void interrupt hex2f(unsigned bp,unsigned  di,unsigned    si,unsigned  ds,
  143.                 unsigned  es,unsigned  dx,unsigned  cx,unsigned  bx,
  144.                 unsigned  ax,unsigned  ip,unsigned  cs,unsigned  flags)
  145. {
  146.     if(ax==0x4b01)
  147.     {
  148.         asm pushf
  149.         (*callback)();
  150.         cbinfo.dd1=MK_FP(_ES,_BX);
  151.         asm mov ax,ds
  152.         es=_AX;
  153.         asm mov ax, offset cbinfo;
  154.         bx=_AX;
  155.     }
  156. }
  157.  
  158.  
  159.